package org.NooLab.docserver.component;

import java.io.File;
import java.util.ArrayList;

import org.NooLab.docserver.properties.ControlSettingsSection;
import org.NooLab.docserver.properties.DocoControlProperties;
import org.NooLab.docserver.properties.DocumentObserverProperties;
import org.NooLab.utilities.strings.StringsUtil;

public class DocoConstraintChecker {

	DocumentObserverProperties docoProperties;
	DocoControlProperties docoControlProperties;
	ArrayList<String> controlInclExt ;
	
	public DocoConstraintChecker(DocumentObserverProperties docoProps){
		docoProperties = docoProps;
		docoControlProperties = docoProperties.getControlProperties() ;
	}
	
	public boolean folderConstraintExtensionSatisfied(String dirname) {
		
		boolean rB=false;
		ControlSettingsSection exts ;
		
		exts = docoControlProperties.getIncludedExtensions();
		controlInclExt = exts.getAttributes();

		File fdir = new File(dirname) ;
		
		File[] files = fdir.listFiles();
		
		for (int i=0;i<files.length;i++){
			String ext = StringsUtil.getExtensionFromFilename(files[i].getName()) ;
			if (controlInclExt.indexOf(ext)>=0){
				rB=true;
				break;
			}
			
		}// i->
		
		
		return rB;
	}
	
}
